package org.fortasoft.hatfield.vmware;

import java.io.FileInputStream;
import java.io.IOException;
import java.net.URL;
import java.util.Properties;

import com.vmware.vim25.VirtualMachineCapability;
import com.vmware.vim25.VirtualMachineConfigInfo;
import com.vmware.vim25.mo.*;

/**
 * Hello world!
 * 
 */
public class App {
	
	static Properties loadAuthProperties() throws IOException {
	
		FileInputStream fis = new FileInputStream("auth.properties");
		Properties p = new Properties();
		p.load(fis);
		fis.close();
		return p;
	
		
	}
	public static void main(String[] args) throws Exception {
		
		Properties props = loadAuthProperties();
		
		ServiceInstance si = new ServiceInstance(new URL(
				props.getProperty("url")), props.getProperty("username"), props.getProperty("password"), true);

		Folder rootFolder = si.getRootFolder();

		ManagedEntity[] mes = new InventoryNavigator(rootFolder)
				.searchManagedEntities("VirtualMachine");
		if (mes == null || mes.length == 0) {
			return;
		}

		for (int i = 0; i < mes.length; i++) {
			VirtualMachine vm = (VirtualMachine) mes[i];

			VirtualMachineConfigInfo vminfo = vm.getConfig();
			VirtualMachineCapability vmc = vm.getCapability();
			System.out.println(vm.getConfig().uuid);
			
			vm.getResourcePool();
			System.out.println("Hello " + vm.getName());
			System.out.println("GuestOS: " + vminfo.getGuestFullName());
			System.out.println("Multiple snapshot supported: "
					+ vmc.isMultipleSnapshotsSupported());

			System.out.println(si.getRootFolder().getName());
		}
	}
}
